<?php

// +----------------------------------------------------------------------
// | TAODUDU.COM  [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.taodudu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: ubten <462193409@qq.com> http://www.ubten.com/
// +----------------------------------------------------------------------

namespace User\Controller;
use User\Controller\BaseController;


class CouponController extends BaseController {
    
    //显示用户购物券
    public function index(){
        
        $user_id = session("user_id");
        $where['voucher_owner_id'] = $user_id;
        $where['voucher_state'] = 1;
        $where['voucher_end_date'] = array('gt',time());
        $p_voucher = M('p_voucher')->where($where)->select();
        $this->assign('voucher',$p_voucher);

        //显示店铺推荐商品
        $where1['voucher_owner_id'] = $user_id;
        $where1['voucher_end_date'] = array('lt',time());
        $e_voucher = M('p_voucher')->where($where1)->select();
        $this->assign('evoucher',$e_voucher);
        $this->assign('active','coupon');
        $this->display();
    }

    //删除用户购物券
    public function delCoupon(){
        $where['voucher_owner_id'] = session("user_id");
        $where['voucher_id'] = I('voucher_id');
        $re = M('p_voucher')->where($where)->delete();
        if($re){
            $a['status'] = TRUE;
            $a['info'] = "删除成功";
        }else{
            $a['status'] = TRUE;
            $a['info'] = "删除成功";
        }
        $this->ajaxReturn($a);
    }
}
